package com.exercise.widgets.dialog.dialogfragment

import android.app.Dialog
import android.content.res.Resources
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.Window
import android.view.WindowManager.LayoutParams
import androidx.fragment.app.DialogFragment
import com.exercise.widgets.R

class FullScreenDialogFragment : DialogFragment() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setStyle(STYLE_NO_TITLE,0)
    }
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.purchase_items, container, false)
    }

    override fun onStart() {
        super.onStart()
        val screenSize = Resources.getSystem().displayMetrics.let {
            it.widthPixels to it.heightPixels
        }

        val win = dialog?.window
        // 设置Dialog的宽高
        val lp = win?.attributes?.apply {
            width = (screenSize.first * 0.8).toInt()
            height = LayoutParams.WRAP_CONTENT
            this.dimAmount = 0.8f
        }
        win?.attributes = lp
        // 设置动画
        win?.setWindowAnimations(R.style.Animation_SlideFromTop)
        win?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
    }




    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        return super.onCreateDialog(savedInstanceState).apply {
            requestWindowFeature(Window.FEATURE_NO_TITLE)
        }
    }

}